#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import sys
from sqlalchemy import Column, Integer, String, Sequence
from db import Base

class UnicodeMixin(object):
    """Mixin class to handle defining the proper __str__/__unicode__
    methods in Python 2 or 3."""
    if sys.version_info[0] >= 3: # Python 3
        def __str__(self):
            return self.__unicode__()
    else:  # Python 2
        def __str__(self):
            return self.__unicode__().encode('utf8')

class UserMixin(UnicodeMixin):
    id = Column(Integer, primary_key=True)
    account = Column(String(128))
    password = Column(String(128))
    def __unicode__(self):
        return u'\t'.join([self.account, self.password])

class User12306cn(UserMixin, Base):
    __tablename__ = '12306cn'
    name = Column(String(32))
    idnum = Column(String(32))
    nickname = Column(String(64))
    phone = Column(String(12))

class UserWangYi(UserMixin, Base):
    __tablename__ = 'wangyi_100w'

class UserMao(UserMixin, Base):
    __tablename__ = 'mao_1000w'

class UserShengDa(UserMixin, Base):
    __tablename__ = 'shengda_1000w'

class User178com(UserMixin, Base):
    __tablename__ = '178com_1000w'

class UserCSDN(UserMixin, Base):
    __tablename__ = 'csdn_600w'
    email = Column(String(64))

class UserDuoWan(UserMixin, Base):
    __tablename__ = 'duowan_800w'
    nickname = Column(String(64))
    email = Column(String(64))

class User7k7k(UserMixin, Base):
    __tablename__ = '7k7k_2000w'

class UserDuDuNiu(UserMixin, Base):
    __tablename__ = 'duduniu'
    email = Column(String(64))

class User17173com(UserMixin, Base):
    __tablename__ = '17173com'
    email = Column(String(64))
    password_md5 = Column(String(32))

class UserTianYa(UserMixin, Base):
    __tablename__  = 'tianya_4000w'
    email = Column(String(64))

class User163com(UserMixin, Base):
    __tablename__ = '163com'

class User163mail(UserMixin, Base):
    __tablename__ = '163mail'

_ALL_MODELS = [
        User12306cn,
        UserWangYi,
        UserMao,
        UserShengDa,
        User178com,
        UserCSDN,
        UserDuoWan,
        User7k7k,
        UserDuDuNiu,
        User17173com,
        UserTianYa,
        User163com,
        User163mail,
        ]

def get_model(index):
    try:
        M = _ALL_MODELS[int(index)]
    except (ValueError, IndexError):
        M = None
    return M
